/***************
 * Import Summary Panel
 */
AIR2.Import.Summary = function() {
    var tools, panel;
    if (AIR2.Import.TANKDATA.radix.tank_type == 'C') {
        // determine if the upload button should be visible
        var mayUpload = false;
        var owner = AIR2.Import.TANKDATA.radix.User.user_uuid;
        if (AIR2.USERINFO.type == 'S' || AIR2.USERINFO.uuid == owner) {
            mayUpload = true;
        }
        tools = ['->',{
            xtype: 'air2button',
            air2type: 'CLEAR',
            iconCls: 'air2-icon-fileup',
            hidden: !mayUpload,
            tooltip: 'Upload CSV',
            handler: function() {
                var w = AIR2.Upload.Modal({
                    originEl: this.el,
                    tankRec: panel.store.getAt(0)
                });
                w.on('close', function() {
                    panel.reload();
                });
            }
        }];
    }
    else {
        tools = [];
    }

    panel = new AIR2.UI.Panel({
        id: 'air2-import-summary-panel',
        storeData: AIR2.Import.TANKDATA,
        url: AIR2.Import.TANKURL,
        colspan: 1,
        title: 'Summary',
        iconCls: 'air2-icon-import',
        itemSelector: '.air2-import-summary',
        tools: tools,
        tpl: new Ext.XTemplate(
            '<tpl for="."><ul class="air2-import-summary">' +
              '<li>' +
                '{[AIR2.Format.tankType(values)]}' +
                '<b>{[AIR2.Format.tankName(values)]}</b>' +
              '</li>' +
              '<li><p><b>Notes: </b>{tank_notes}</p></li>' +
              '<li>' +
                '<b>User: </b>{[AIR2.Format.userName(values.User,true)]}' +
              '</li>' +
              '<li>' +
                '<b>Created: </b>{[AIR2.Format.date(values.tank_cre_dtim)]}' +
              '</li>' +
              '<li><br/></li>' +
              '<li>{[this.formatMeta(values)]}</li>' +
              '<li><br/></li>' +
              '<li>' +
                '<b>Status: </b>' +
                '{[AIR2.Format.tankStatus(values)]}' +
                '{[AIR2.Format.tankStatus(values, true)]}' +
                '<p><b>{count_total} Sources</b> ({count_done} imported, {count_conflict} conflicts)</p>' +
              '</li>' +
            '</ul></tpl>',
            {
                compiled: true,
                disableFormats: true,
                formatMeta: function(tank) {
                    var meta = Ext.decode(tank.tank_meta);
                    if (tank.tank_type == 'C') {
                        return '<p><b>File Size:</b> '+meta.file_size+'</p>' +
                            '<p><b>Upload Msg:</b> '+meta.submit_message+'</p>';
                    }
                    return '<p>Formbuilder Import</p>';
                }
            }
        )
    });
    return panel;
}